-- @owner:songfei_st
-- @date:2024-5-27
-- @testpoint:1.合理报错，开启预编译参数，创建带有rowtype的触发器,部分用例合理报错          


--创建一个表，用来存需验证的数据
create table t_Compare_Case0016(first_name varchar(100), last_name varchar(100));

--step1:开启预编译参数
set behavior_compat_options='allow_procedure_compile_check';

--step2:创建表;expect:成功
create table t_CurRowtype_PLObject_Case0016(first_name varchar(100), last_name varchar(100));
insert into t_CurRowtype_PLObject_Case0016 values('Jason','Statham');

--step3:创建带有rowtype的触发器函数;expect:成功
create or replace function f_CurRowtype_PLObject_Case0016() returns trigger as
$$
declare
  cursor cur_1 is select * from t_CurRowtype_PLObject_Case0016;
  source cur_1%rowtype;
begin
   source.first_name:=new.first_name;
   source.last_name:=new.last_name;      
   insert into t_Compare_Case0016 values (source.first_name,source.last_name);
   return new;
end
$$ language plpgsql;
/

--step4:创建INSERT触发器;expect:成功
create trigger tri_CurRowtype_PLObject_Case0016 before insert on t_CurRowtype_PLObject_Case0016 for each row
execute procedure f_CurRowtype_PLObject_Case0016();/

--step5:调用触发器;expect:成功
insert into t_CurRowtype_PLObject_Case0016 values('Jason_New','Statham_New');

--step6:查询数据;expect:成功(1 row)
select * from t_Compare_Case0016;

--清理环境;expect:成功(4 rows)
drop trigger tri_CurRowtype_PLObject_Case0016 on t_CurRowtype_PLObject_Case0016;
drop function f_CurRowtype_PLObject_Case0016;
drop table t_Compare_Case0016;
drop table t_CurRowtype_PLObject_Case0016;
--重置参数
reset all;